package com.yourenbang.lingyun.transaction.web.controller.manage;

import com.yourenbang.lingyun.core.base.controller.BaseController;
import com.yourenbang.lingyun.core.base.interceptor.ExcludeInterceptor;
import com.yourenbang.lingyun.core.message.Result;
import com.yourenbang.lingyun.core.model.vo.PageVO;
import com.yourenbang.lingyun.core.util.KLog;
import com.yourenbang.lingyun.transaction.web.service.manage.ManageService;
import com.yourenbang.lingyun.transaction.web.service.pay.withdraw.WithdrawPayService;
import com.yourenbang.lingyun.transaction.web.service.yxy.YxyTradeService;
import com.yourenbang.transaction.api.model.dto.manage.*;
import com.yourenbang.transaction.api.model.vo.manage.QueryPledgeDetailVO;
import com.yourenbang.transaction.api.model.vo.manage.QueryWithdrawDetailVO;
import com.yourenbang.transaction.api.model.vo.manage.QueryWithdrawTerVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description
 * @Date 2020/10/30 10:02
 * @Created by Jason
 */

@Slf4j
@RestController
@RequestMapping("/transaction/manage")
public class ManageController extends BaseController {

    @Autowired
    private ManageService manageService;
    @Autowired
    private WithdrawPayService withdrawPayService;
    @Autowired
    private YxyTradeService yxyTradeService;


    /**
     * 导出机具对应提现表数据
     */
    @ExcludeInterceptor
    @GetMapping(value = "/export/withdraw/record")
    public void topupApply(QueryWithdrawTerDTO dtoRequest) {

        KLog.info("[导出机具对应提现表数据入参]:{}", dtoRequest);
        manageService.exportDayWithdrawReport(dtoRequest);
        return;
    }

    /**
     * 查询机具对应提现表数据
     *
     * @return
     */
    @ExcludeInterceptor
    @GetMapping(value = "/get/withdraw/record")
    public Result<List<QueryWithdrawTerVO>> getDayWithdrawReport(QueryWithdrawTerDTO dtoRequest) {

        KLog.info("[查询机具对应提现表数据入参]:{}", dtoRequest);
        return manageService.getDayWithdrawReport(dtoRequest);
    }

    /**
     * 导出机具对应提现表数据-网商
     */
    @ExcludeInterceptor
    @GetMapping(value = "/export/withdraw/record/ws/{dayNum}")
    public void exportDayWithdrawReportWs(@PathVariable("dayNum") Integer dayNum) {

        KLog.info("[导出机具对应提现表数据-网商入参]:{}", dayNum);
        manageService.exportDayWithdrawReportWs(dayNum);
        return;
    }
    /**
     * 导出机具对应提现表数据-喜乐付
     *
     * @return
     */
    @ExcludeInterceptor
    @GetMapping(value = "/export/withdraw/record/xlf/{dayNum}")
    public void exportDayWithdrawReportXlf(@PathVariable("dayNum") Integer dayNum) {

        KLog.info("[导出机具对应提现表数据-xlf入参]:{}", dayNum);
        manageService.exportDayWithdrawReportXlf(dayNum);
        return;
    }

    /**
     * 查询提现订单
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/2138">火眼接口</a>
     * @param dto
     * @return
     */
    @ExcludeInterceptor
    @GetMapping("/list/withdraw")
    public Result<PageVO> listWithdraw(QueryWithdrawListDTO dto){
        KLog.info("查询提现订单入参:{}",dto.toString());
        return manageService.listWithdraw(dto);
    }

    /**
     * 导出提现订单
     *
     * @param dto
     */
    @ExcludeInterceptor
    @GetMapping(value = "/export/list/withdraw")
    public void exportListWithdraw(ExportWithdrawListDTO dto){
        KLog.info("导出提现订单入参:{}",dto);
        manageService.exportListWithdraw(dto);
        return;
    }


    /**
     * 查询提现日结订单
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/14193">火眼接口</a>
     * @param dto
     * @return
     */
    @ExcludeInterceptor
    @GetMapping("/list/t1/withdraw/bill")
    public Result<PageVO> listT1WithdrawBill(QueryT1WithdrawBillDTO dto){
        KLog.info("查询提现日结订单入参:{}",dto.toString());
        return manageService.listT1WithdrawBill(dto);
    }

    /**
     * 导出提现日结订单
     *
     * @param dto
     */
    @ExcludeInterceptor
    @GetMapping("/export/list/t1/withdraw/bill")
    public void exportListT1WithdrawBill(ExportT1WithdrawBillDTO dto){
        KLog.info("导出提现日结订单入参:{}",dto);
        manageService.exportListT1WithdrawBill(dto);
        return;
    }


    /**
     * 查询提现订单详情
     *
     * @param
     * @return
     */
    @ExcludeInterceptor
    @GetMapping("/detail/withdraw")
    public Result<QueryWithdrawDetailVO> detailWithdraw(@RequestParam("fundAccountWithdrawPaymentId") Integer fundAccountWithdrawPaymentId
    ,@RequestParam("platNo") Integer platNo){
        KLog.info("查询提现订单详情入参:{},platNo:{}",fundAccountWithdrawPaymentId,platNo);
        return manageService.detailWithdraw(fundAccountWithdrawPaymentId,platNo);
    }

    /**
     * 查询押金列表
     *
     * @param dto
     * @return
     */
    @ExcludeInterceptor
    @GetMapping("/list/pledge")
    public Result<PageVO> listPledge(QueryPledgeListDTO dto){
        KLog.info("查询押金列表入参:{}",dto);
        return manageService.listPledge(dto);
    }

    /**
     * 导出押金列表
     *
     * @param dto
     * @return
     */
    @ExcludeInterceptor
    @GetMapping("/export/list/pledge")
    public void exportListPledge(ExportPledgeListDTO dto){
        KLog.info("导出押金列表入参:{}",dto);
        manageService.exportListPledge(dto);
        return;
    }

    /**
     * 查询押金详情
     *
     * @param merchantId
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/2154">火眼</a>
     * @return
     */
    @ExcludeInterceptor
    @GetMapping("/detail/pledge")
    public Result<QueryPledgeDetailVO> detailPledge(String merchantId){
        KLog.info("查询押金详情入参:{}",merchantId);
        return manageService.detailPledge(merchantId);
    }

    /**
     * 次日结算提现发放
     *
     * @param batchNumber
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/14196">火眼</a>
     * @return
     */
    @ExcludeInterceptor
    @GetMapping("/withdraw/pay")
    public Result withdrawPay(String batchNumber){
        KLog.info("次日结算发放提现入参:{}",batchNumber);
        Result result = withdrawPayService.withDrawT1Pay(batchNumber);
        KLog.info("次日结算发放提现入参:{},返回:{}",batchNumber,result.toString());
        return result;
    }
}

